from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field
from enum import Enum


class ServiceType(str, Enum):
    application = 'application'
    database = 'database'
    bigdata = 'bigdata'


class excludeKeyword(BaseModel):
    username: str = Field(..., description="申请人")
    exclude_keyword: Optional[str] = Field(None, description="排除关键字")
    is_active: int = Field(0, description="屏蔽关键字状态: true(开启) / false(关闭)")
    effective_datetime: Optional[datetime] = Field(None, description="关键字屏蔽生效时间")
    expiration_datetime: Optional[datetime] = Field(None, description="关键字屏蔽失效时间")


class CreateAlarmService(BaseModel):
    service_name: str = Field(..., regex="^[-.a-zA-Z0-9_]+$", description="服务名称")
    type: ServiceType = Field(..., description="服务类型:application(应用服务) or database(数据库) or bigdata(大数据)")
    alarm_threshold: int = Field(50, description="告警阈值默认50")
    alarm_plan: dict = Field(None, description="告警时间计划")
    is_maintain: int = Field(0, description="维护状态:1(开启) / 0(关闭)")
    maintain_begin_time: Optional[datetime] = Field(None, description="维护开始时间")
    maintain_end_time: Optional[datetime] = Field(None, description="维护结束时间")
    exclude_keywords: List[excludeKeyword] = Field(None, description="排除关键字")
    notice_group: Optional[List[int]] = Field(None, description="关联通知组uuid")


class UpdateAlarmService(BaseModel):
    uuid: int = Field(..., description="服务uuid")
    type: ServiceType = Field(..., description="服务类型:application(应用服务) or database(数据库) or bigdata(大数据)")
    alarm_threshold: int = Field(50, description="告警阈值默认50")
    alarm_plan: dict = Field(None, description="告警时间计划")
    is_maintain: int = Field(1, description="维护状态:1(开启) / 0(关闭)")
    maintain_begin_time: Optional[datetime] = Field(None, description="维护开始时间")
    maintain_end_time: Optional[datetime] = Field(None, description="维护结束时间")
    exclude_keywords: List[excludeKeyword] = Field(None, description="排除关键字")
    notice_group: Optional[List[int]] = Field(None, description="关联通知组uuid")


class DeleteUuid(BaseModel):
    uuid: int = Field(..., description="uuid")


class ModifyAlarmAppIsMaintain(BaseModel):
    uuid: int = Field(..., description="服务uuid")
    is_maintain: int = Field(1, description="维护状态:1(开启) / 0(关闭)")



class DelBaseModel(BaseModel):
    uuid: int = Field(..., description="数据的uuid")
    
    
class PutHttpUrl(BaseModel):
    uuid: int = Field(..., description="数据的uuid")
    domain: Optional[str] = Field("", description="接口域名")
    url: Optional[str] = Field("", description="接口url")
    method: Optional[str] = Field("", description="接口方法")
    department: Optional[str] = Field("", description="所属部门")
    production: Optional[str] = Field("", description="所属产品")
    module: Optional[str] = Field("", description="所属模块")
    provider: Optional[str] = Field("", description="服务提供者")
    is_use: int = Field(1, description="使用状态:1(开启) / 0(关闭)")
    comment: Optional[str] = Field("", description="接口说明")